import bpy

from 节点.全局控制.Node.节点和插座基类 import bl_节点基类

import Core.bl_UI配色 as UI配色

import engine.initLIB.load_dll as engineLib
import ctypes





engineLib.flexCAPI.f_创建排序节点.restype = ctypes.c_bool











E_排序方式枚举 = [
	("TYPE_排序_升序", "升序", "", 0),
	("TYPE_排序_降序", "降序", "", 1),
	("TYPE_排序_逆序", "逆序", "", 2),
	("TYPE_排序_乱序", "乱序", "", 3),
]

def f_update_排序方式(self, context):
	data = list(str(self.m_排序方式))
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));
	if context :
		self.id_data.f_节点数据更新_更新树([self])

class C_Node_排序(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_排序'
	bl_label = '排序'
	bl_icon = 'FILE_IMAGE'

	m_排序方式 = bpy.props.EnumProperty(items=E_排序方式枚举, name="方式", default="TYPE_排序_升序", update=f_update_排序方式)
	def init(self, context):
		super(C_Node_排序, self).f_init(context)
		self.inputs.new('C_Socket_引用', name='list')
		self.inputs.new('C_Socket_I32', name='种子')
		self.outputs.new('C_NodeSocket_动态插座', name='list')
		self.f_toCPP(self.id_data)
		
	
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建排序节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			f_update_排序方式(self, None)
			
			self.use_custom_color = True
			self.color = UI配色.g_内部节点颜色
		
	def draw_buttons(self, context, layout):
		layout.prop(self, "m_排序方式", text="方式")
		
		
class C_NODE_MENU_排序(bpy.types.Operator):
	bl_idname = 'node.create_node_sort'
	bl_label = '排序'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(self, context):
		bpy.ops.node.add_node(type='C_Node_排序', use_transform=True)
		return {'FINISHED'}
		








classes = (
	C_Node_排序,
	C_NODE_MENU_排序,
	
)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)





